<!doctype html>
<html lang="zh-hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>websocket的当前时间</title>
</head>
<body>
  <h1></h1>
  <script>
      var h1=document.querySelector("h1");
      var url="ws://127.0.0.1:8080/chatroom/ws-now";
      //websocket对象创建成功，就隐含着，信道开启了
      var ws=new WebSocket(url);
      ws.onmessage=function (e) {
          var now=e.data;//收到的数据保存在data中
          h1.innerText=now;
      }
  </script>
</body>
</html>